package org.shuma.email.impl;

import com.alipay.sofa.runtime.api.annotation.SofaService;
import com.alipay.sofa.runtime.api.annotation.SofaServiceBinding;

import org.shuma.email.facade.SendMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

/**
 * @author zhao haitao
 * @date 2024/06/16 3:16 PM
 */
@Service
@SofaService(interfaceType = SendMessage.class, uniqueId = "${service.unique.id}", bindings = {@SofaServiceBinding(bindingType = "bolt")})
public class SendMessageImpl implements SendMessage {
    @Autowired
    private JavaMailSender javaMailSender;
    @Value("${spring.mail.username}")
    private String MAIL_SENDER;

    @Override
    public void sendCommonMessage(String email, String subject, String message) {
        // 发送邮件
        SimpleMailMessage mail = new SimpleMailMessage();
        mail.setTo(email);
        mail.setFrom(MAIL_SENDER);
        mail.setSubject(subject);
        mail.setText(message);
        javaMailSender.send(mail);
    }
}
